import type { PropType } from 'vue';

export interface OptionItemSelect {
  value: string | number;
  label: string;
  [key: string]: unknown;
}

export const apiSelectProps = {
  /**
   * 类型定义
   */
  valueType: {
    type: String as PropType<'object' | 'string'>,
    default: 'string',
  },
  remoteApi: {
    type: Function as PropType<
      (params?: Record<string, any>) => Promise<OptionItemSelect[]>
    >,
  },
  multiple: {
    type: Boolean as PropType<boolean>,
    default: false,
  },
  allowSearch: {
    type: Boolean as PropType<boolean>,
    default: false,
  },
  isSearch: {
    type: Boolean as PropType<boolean>,
    default: false,
  },
  modelValueField: {
    type: String as PropType<string>,
    default: 'value',
  },
  labelField: {
    type: String as PropType<string>,
    default: 'label',
  },
  valueField: {
    type: String as PropType<string>,
    default: 'value',
  },
  resultField: {
    type: String as PropType<string>,
  },
  modelValue: {
    type: [String, Number, Object, Array] as PropType<
      | string
      | number
      | OptionItemSelect
      | (string | number | OptionItemSelect)[]
    >,
  },
  params: {
    type: Object as PropType<Record<string, any>>,
  },
  immediate: {
    type: Boolean as PropType<boolean>,
    default: true,
  },
  searchType: {
    type: String as PropType<'local' | 'remote'>,
    default: 'remote',
  },
};
